package com.hanhanxiaochong.zhongxiangchuanmei.view.my.act;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.util.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/6/11.
 * Desc   :
 */

public class InputBankAdressDialog extends DialogFragment {

    @BindView(R.id.et_input_bankaddress)
    EditText etInputBankaddress;
    private View view;
    private InputBankAddressListener inputBankAddressListener;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        //去掉dialog的标题，需要在setContentView()之前
        this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = this.getDialog().getWindow();
        //去掉dialog默认的padding
        assert window != null;
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.8f);
        //设置dialog的动画
//        lp.windowAnimations = R.style.BottomDialogAnimStyle;
        window.setAttributes(lp);
        window.setBackgroundDrawable(new ColorDrawable());
        view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_input_bankaddress, null);
        ButterKnife.bind(this,view);
        return view;
    }

    @OnClick(R.id.txt_confirm)
    public void onViewClicked() {
        String address = etInputBankaddress.getText().toString();
        if (StringUtils.isEmpty(address)){
            dismiss();
            inputBankAddressListener.confirmClick(address);
        }else {
            Toast.makeText(getContext(), "请输入开户网点", Toast.LENGTH_SHORT).show();
        }
    }

    public interface InputBankAddressListener{
        void confirmClick(String bankAddress);
    }

    public void setInputBankAddressListener(InputBankAddressListener inputBankAddressListener){
        this.inputBankAddressListener = inputBankAddressListener;
    }
}
